package com.sdtele.tta.operation;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sdtele.tta.dac.Dac;
import com.sdtele.tta.models.JsonRequest;
import com.sdtele.tta.models.JsonResponse;
import com.sdtele.tta.models.User;
import com.sdtele.tta.models.VoteOperation;
import com.sdtele.tta.models.VoteOption;
import com.sdtele.tta.models.VoteTask;

public class OperationGetVote extends Operation {
	public JsonResponse handle(JsonRequest jsonRequest) {
		System.out.println("OperationLogin:req=" + jsonRequest);
		JsonResponse jres = new JsonResponse();
		User curUser = (User) request.getSession().getAttribute("user");
		if (curUser == null) {
			jres.setStatus(1);
			jres.setMessage("用户登录失效,请重新登录");
		} else {
			Map<String, Object> voteMap = new HashMap<String, Object>();
			long voteId=jsonRequest.getJsonObject().get("voteId").getAsLong();
			VoteTask voteTask=Dac.getInstance().getVoteTaskbyVoteid(voteId);
			System.out.println("测试一下"+voteTask);
			List<User> voteImpList =Dac.getInstance().getVoteOperationbyImpelement(voteId);
			List<User> voteReaList=Dac.getInstance().getVoteOperationbyReader(voteId);
			List<VoteOption> voteOp=Dac.getInstance().getVoteOption(voteId);
			User user=Dac.getInstance().getUser(voteTask.getOwnerId());
			voteMap.put("voteTask", voteTask.ToVoteTaskOut());
			voteMap.put("user", user);
			voteMap.put("voteImpList", voteImpList);
			voteMap.put("voteReaList", voteReaList);
			voteMap.put("voteOp", voteOp);
			jres.setStatus(0);
			jres.setMessage("投票任务详情");
			jres.setEntity(voteMap);
		}
		return jres;
	}

}